﻿

using Microsoft.Extensions.Configuration;
using Orleans.Concurrency;
using Orleans.Placement;
using Grain.Strategy;

namespace OrleansDemo.Grain
{
    // [SamplePlacementStrategy]
    // [StatelessWorker]
    public class HelloGrain2 : Orleans.Grain, IHello2
    {
        public static string ServerId { get; set; }

        private int _count = 0;

        private static long _key = 0;

        public HelloGrain2()
        {

        }

        public async Task<string> SayHello(string greeting)
        {
            Interlocked.Increment(ref _key);
            var result = await GrainFactory.GetGrain<IHello>(_key % 3).SayHello(greeting);
            return $"{ServerId} IHello2调用IHello {result}";

            //await Task.Delay(10);
            //Console.WriteLine($"{ServerId} SayHello2 message received: greeting = '{greeting}'");
            //return $" {ServerId} You said: '{greeting}', I say: Hello! count={_count++}";
        }
    }
}
